//
//  TopUpViewController.m
//  KuWeiPark
//
//  Created by Kevin Su on 15/5/25.
//  Copyright (c) 2015年 Clief. All rights reserved.
//

#import "TopUpViewController.h"
#import "AmountButton.h"
#import "TopUpPaywaysController.h"

@interface TopUpViewController ()

@end

@implementation TopUpViewController{
    
    NSString *topUpAmount; // 充值的金额
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.payBtn.layer.masksToBounds = YES;
    self.payBtn.layer.cornerRadius = 5;
    
    [self initAmountButtons];
}

//初始化金额按钮
- (void)initAmountButtons{
    
    for(UIView *view in self.buttonsView.subviews){
        
        if([view isKindOfClass:[AmountButton class]]){
            
            AmountButton *btn = (AmountButton *)view;
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = btn.frame.size.width / 2.0;
            [btn addTarget:self action:@selector(amountBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
            
            if(btn.tag - 10000 == 20){
                
                //20 元
                [btn setSelected:YES];
                topUpAmount = [NSString stringWithFormat:@"%d", btn.tag - 10000];
            }else{
                
                [btn setSelected:NO];
            }
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - IBActions
- (IBAction)back:(id)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)amountBtnClicked:(AmountButton *)button{
    
    for(UIView *view in self.buttonsView.subviews){
        
        if([view isKindOfClass:[AmountButton class]]){
            
            AmountButton *btn = (AmountButton *)view;
            if([btn isEqual:button]){
                
                [btn setSelected:YES];
                topUpAmount = [NSString stringWithFormat:@"%d", btn.tag - 10000];
            }else{
                
                [btn setSelected:NO];
            }
        }
    }
}

- (IBAction)showPayView:(id)sender {
    
    //显示支付方式页面
    TopUpPaywaysController *topUpPaywaysController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"TopUpPaywaysController"];
    topUpPaywaysController.payAmount = topUpAmount;
    [self.navigationController pushViewController:topUpPaywaysController animated:YES];
}


@end
